package pta;

import java.util.ArrayList;
import java.util.Scanner;

public class java8_6 {

	public static void main(String[] args) {
		int count = 0;
		int i = 0;
		ArrayList strList = new ArrayList();
		Scanner sc = new Scanner(System.in);
		
		strList.add(0, sc.next());
		for(i = 0; strList.get(i).equals ("!!end!!") != true;i++)//111
		{  
			strList.add(i+1, sc.next());
			
		    count++;
		}
		strList.remove(i);
		
		strList.add(0, "begin");// 222
		strList.add("end");
		System.out.println(strList);// 333

		String str1 = sc.next();// 444

		System.out.println(strList.contains(str1));//555
		System.out.println(strList.indexOf(str1) );
		System.out.println(strList.lastIndexOf(str1) );//666
		System.out.println(strList.get(0));// 777
		strList.remove(0);
		System.out.println(strList);
		

		String str2 = sc.next();// 888

		// 999
		strList.add(1, str2);
		strList.remove(2);

		System.out.println(strList);// 10

		String str3 = sc.next();// 11

		ArrayList strList1 = new ArrayList();// 12
		for (i = 0; i < count; i++)
		{    
		
			if (((String)strList.get(i)).indexOf(str3) != -1)
				strList1.add(strList.get(i));
		}

		System.out.println(strList1);
		
		int nn = strList.indexOf(str3);
         if(nn!=-1)
		   strList.remove(nn);
        	 
		System.out.println(strList);// 14

		strList.clear();// 15
		System.out.printf("%s %d,%b", strList, strList.size(), strList.isEmpty());

	}

}
